package com.example.springmvc.demos.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

//@RestController  返回的其实是一个数据
//RestController是ResponseBody加上Controller
//返回视图的话，需要把ResponseBody去掉
//ResponseBody代表返回text信息
//ResponseBody即是类注解也是方法注解，加到类上表示该类的所有方法都是返回数据
@Controller
public class IndexController {
    @RequestMapping("/index")
    public Object index(){
        return "/index.html";
    }

    @RequestMapping("/return")
    @ResponseBody
    public String returndata(){
        return "该方法返回数据";
    }

    @RequestMapping("/returnhtml")
    @ResponseBody
    public String returnhtml(){
        return "<h1>Hello Html~<h1>";
    }


    @RequestMapping("/returnjson")
    @ResponseBody
    public HashMap<String,String> returnJson(){
        HashMap<String,String> map=new HashMap<> ();
        map.put ("Java","value1");
        map.put ("C","value2");
        map.put ("Python","value3");
        return map;

    }


}
